unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdIOHandlerSocket,
  IdBaseComponent, IdComponent, IdTCPServer, IdMappedPortTCP, StdCtrls,
  IdIOHandler, IdIOHandlerThrottle, Spin;

type
  TformMain = class(TForm)
    IdMappedPortTCP1: TIdMappedPortTCP;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Label5: TLabel;
    procedure IdMappedPortTCP1Connect(AThread: TIdMappedPortThread);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  formMain: TformMain;
  GSpeed: Integer = 0;

implementation
{$R *.dfm}

uses
  IdTCPConnection,
  MyDebugger,
  ShellAPI;

procedure TformMain.IdMappedPortTCP1Connect(AThread: TIdMappedPortThread);
var
  LClient: TIdTCPConnection;
  LDebugger: TMyDebugger;
begin
  LClient := AThread.OutboundClient;
  LDebugger := TMyDebugger.Create(LClient);
  LDebugger.BytesPerSecond := SpinEdit1.Value * 600;
  LClient.IOHandler := LDebugger;
end;

procedure TformMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 IdMappedPortTCP1.Active := false;
end;

procedure TformMain.Button1Click(Sender: TObject);
begin
  if Button1.Caption = 'Start'
  then begin
       Button1.Caption := 'Stop';
       Caption := 'Running';
       IdMappedPortTCP1.MappedHost := 'localhost';
       IdMappedPortTCP1.MappedPort := StrToIntDef(Edit1.Text, 80);
       IdMappedPortTCP1.DefaultPort := StrToIntDef(Edit2.Text, 8081);
       IdMappedPortTCP1.Active :=  True;
       end
  else begin
       IdMappedPortTCP1.Active :=  False;
       Caption := 'Stoped';
       Button1.Caption := 'Start';
       end;
end;

end.
